<?php

/**
 * This is the model class for table "percepcion".
 *
 * The followings are the available columns in table 'percepcion':
 * @property integer $cliente
 * @property integer $contribuyenteRN
 * @property integer $convenio_multilateral
 * @property integer $jusrisdiccionRN
 * @property string $coeficiente
 * @property integer $nro_iibb
 * @property integer $situacion
 *
 * The followings are the available model relations:
 * @property Cliente $cliente0
 */
class Percepcion extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'percepcion';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('cliente, contribuyenteRN, convenio_multilateral, jusrisdiccionRN, coeficiente, nro_iibb, situacion', 'required'),
			array('cliente, contribuyenteRN, convenio_multilateral, jusrisdiccionRN, nro_iibb, situacion', 'numerical', 'integerOnly'=>true),
			array('coeficiente', 'length', 'max'=>5),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('cliente, contribuyenteRN, convenio_multilateral, jusrisdiccionRN, coeficiente, nro_iibb, situacion', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'cliente0' => array(self::BELONGS_TO, 'Cliente', 'cliente'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'cliente' => 'Cliente',
			'contribuyenteRN' => 'Contribuyente RN',
			'convenio_multilateral' => 'Convenio Multilateral',
			'jusrisdiccionRN' => 'Jusrisdiccion RN',
			'coeficiente' => 'Coeficiente',
			'nro_iibb' => 'Nro IIBB',
			'situacion' => 'Situacion',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
		$criteria->with = array( 'cliente0' );

		$criteria->compare('cliente0.nombre',$this->cliente,true);
		$criteria->compare('contribuyenteRN',$this->contribuyenteRN);
		$criteria->compare('convenio_multilateral',$this->convenio_multilateral);
		$criteria->compare('jusrisdiccionRN',$this->jusrisdiccionRN);
		$criteria->compare('coeficiente',$this->coeficiente,true);
		$criteria->compare('nro_iibb',$this->nro_iibb);
		$criteria->compare('situacion',$this->situacion);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,'sort'=>array(
					'defaultOrder'=>'cliente0.nombre',)
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Percepcion the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
